/*
PearReview - The peer review assistant.
Copyright (C) 2009  Dimitrij Pankratz, Anton Musichin
http://www.pearreview.com, info@pearreview.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

package com.pearreview.ui;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class BufferedImagePanel extends JPanel{

	private static final long serialVersionUID = -6228733200947115070L;
	private BufferedImage image = null;
	
	public BufferedImagePanel() {
		super();
	}
	
	public BufferedImagePanel(URL image) {
		this();
		try {                
			this.image = ImageIO.read(image);
		} catch (IOException ignore) {
			
		}
	}

	public BufferedImagePanel(BufferedImage image) {
		this();
		setBufferedImage(image);
	}
	
	public void setBufferedImage(BufferedImage image) {
		this.image = image;
	}
	
	public BufferedImage getBufferedImage() {
		return image;
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponents(g);
		Graphics2D g2d  = (Graphics2D)g;
		if (image != null)
			g2d.drawImage(image, 
					0, 
					0, 
					image.getWidth(), 
					image.getHeight(),
					null);
	}
}
